package aryn.framework.display.imageButton;

/**
 * Copyright(c) 1997 DTAI, Incorporated (http://www.dtai.com)
 *
 *                        All rights reserved
 *
 * Permission to use, copy, modify and distribute this material for
 * any purpose and without fee is hereby granted, provided that the
 * above copyright notice and this permission notice appear in all
 * copies, and that the name of DTAI, Incorporated not be used in
 * advertising or publicity pertaining to this material without the
 * specific, prior written permission of an authorized representative of
 * DTAI, Incorporated.
 *
 * DTAI, INCORPORATED MAKES NO REPRESENTATIONS AND EXTENDS NO WARRANTIES,
 * EXPRESS OR IMPLIED, WITH RESPECT TO THE SOFTWARE, INCLUDING, BUT
 * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
 * FITNESS FOR ANY PARTICULAR PURPOSE, AND THE WARRANTY AGAINST
 * INFRINGEMENT OF PATENTS OR OTHER INTELLECTUAL PROPERTY RIGHTS.  THE
 * SOFTWARE IS PROVIDED "AS IS", AND IN NO EVENT SHALL DTAI, INCORPORATED OR
 * ANY OF ITS AFFILIATES BE LIABLE FOR ANY DAMAGES, INCLUDING ANY
 * LOST PROFITS OR OTHER INCIDENTAL OR CONSEQUENTIAL DAMAGES RELATING
 * TO THE SOFTWARE.
 */

import java.awt.*;
import java.applet.*;
import java.net.*;

import aryn.framework.graphic.Load;

public class ImageButtonApplet extends Applet {

    ImageButton button1;
    ImageButton button2;
    ImageButton button3;

    /**
     * initialize the applet
     */
    public void init() {
        try {
            setBackground( Color.lightGray );
            setLayout( new FlowLayout() );
            button1 = new ImageButton( Load.bufferedImage("C:/eclipse SE/workspace/Aryn/imgs/button.jpg") );
            button1.setArmedImage( Load.bufferedImage("C:/eclipse SE/workspace/Aryn/imgs/button_.gif") );
            button1.setOverImage( getImage( new URL( getDocumentBase(), "over.gif" ) ) );
            add( button1 );

            button2 = new ImageButton();
            button2.setUnarmedImage( getImage( new URL( getDocumentBase(), "open_up.gif" ) ) );
            button2.setOverImage( getImage( new URL( getDocumentBase(), "open_over.gif" ) ) );
            button2.setDisabledImage( getImage( new URL( getDocumentBase(), "open_dis.gif" ) ) );

            Border noBorder = (Border)button2.getUnarmedBorder().clone();
            noBorder.setType( Border.NONE );

            button2.setUnarmedBorder( noBorder );
            button2.setDisabledBorder( noBorder );
            add( button2 );

            button3 = new ImageButton();
            button3.setUnarmedImage( getImage( new URL( getDocumentBase(), "save_up.gif" ) ) );
            button3.setOverImage( getImage( new URL( getDocumentBase(), "save_over.gif" ) ) );
            button3.setUnarmedBorder( noBorder );
            button3.setDisabledBorder( noBorder );
            add( button3 );
        }
        catch ( MalformedURLException mue ) {
            mue.printStackTrace();
            showStatus( "URL error trying to load the image" );
        }
    }

    public void start() {
    }

    public void stop() {
    }

    public void destroy() {
    }

    /**
     * handle the button actions
     *
     * @param evt     the event (in this case, the mouse button release) that caused this action
     * @param obj     the action object (we don't need it)
     * @return        true if handled
     */
    public boolean action( Event evt, Object what ) {
        if ( evt.target == button1 ) {
            button2.enable( ! button2.isEnabled() );
            return true;
        }
        else if ( evt.target == button2 ) {
            button1.enable( ! button1.isEnabled() );
            return true;
        }
        else if ( evt.target == button3 ) {
            button1.enable();
            button2.enable();
            return true;
        }
        return false;
    }
}